<template>
    <div class="pdf-container">
      <iframe :src="'@/assets/resumePDF/c86aa60.pdf'" width="100%" height="600px"></iframe>
      <div class="button-container">
        <el-button type="success" @click="handlePass">通过</el-button>
        <el-button type="danger" @click="showNextPdf">不通过</el-button>
      </div>
    </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      pdfNames: [],
      currentIndex: 0,
      currentPdfName: ""
    };
  },
  mounted() {
    axios.get("http://localhost:8080/resume/getpdfs")
  .then(response => {
        this.pdfNames = response.data.data;
        // 初始化时设置当前展示的PDF文件名
        this.currentPdfName = this.pdfNames[this.currentIndex];
      })
  .catch(error => {
        console.error("获取PDF文件名失败:", error);
      });
  },
  methods: {
    getPdfSrc(pdfName) {
      return process.env.BASE_URL + '@/assets/resumePDF/' + pdfName;
    },
    showNextPdf() {
      // 更新当前索引，到达最后一个则循环回到第一个
      this.currentIndex = (this.currentIndex + 1) % this.pdfNames.length;
      // 根据更新后的索引设置当前展示的PDF文件名
      this.currentPdfName = this.pdfNames[this.currentIndex];
    },
    handlePass() {
      axios.post("http://localhost:8080/resume/update-status", `resume_addr=${this.currentPdfName}`, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
        })
    .then(() => {
          // 请求成功后跳转下一页
          this.showNextPdf();
        })
    .catch(error => {
          console.error("更新状态失败:", error);
        });
    }
  }
};
</script>

<style scoped>
.pdf-container {
  text-align: center;
}
.button-container {
  display: inline-block;
}
</style>
